package com.mb.app.controller;

import com.mb.app.domain.TbUserInfo;
import com.mb.app.service.ITbUserInfoService;
import com.mb.common.controller.BaseController;
import com.mb.common.utils.DateUtils;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * @author whl
 * @program
 * @description 用户管理
 * @date 2019-03-23 10:49
 **/
@Controller
@RequestMapping("/app/user")
@Slf4j
public class UserInfoController extends BaseController {
    
    @Autowired
    private ITbUserInfoService userInfoService;

    @GetMapping("/index")
    String index(){
        return "/app/user/user_list";
    }


    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        // 时间截取
        String regTime = (String) params.get("regTime");
        if (StringUtils.isNotEmpty(regTime)) {
            params.put("startTime", DateUtils.parse(regTime.substring(0,10),DateUtils.DATE_PATTERN));
            params.put("endTime",regTime.substring(13,23)+" 23:59:59");
        }
        Query query = new Query(params);
        List<TbUserInfo> list = userInfoService.queryList(query);
        int total = userInfoService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }


    @ResponseBody
    @PostMapping("/remove")
    public R remove(@RequestParam("userId") Long userId, HttpServletRequest request){
        int result = userInfoService.remove(userId);
        return R.ok();
    }

    @ResponseBody
    @PostMapping("/status")
    public R remove(@RequestParam("userId") Long userId,@RequestParam("userstatus") Integer userstatus, HttpServletRequest request){
        int result = userInfoService.status(userId,userstatus);
        return R.ok();
    }

}


